package com.appkubes.mall.admin.application.goods.goods.service.impl;

import com.appkubes.common.utils.data.string.UUIDUtils;
import com.appkubes.mall.admin.application.goods.goods.dao.GoodsAssociateDao;
import com.appkubes.mall.admin.application.goods.goods.entity.dto.GoodsAssociateDTO;
import com.appkubes.mall.admin.application.goods.goods.service.GoodsAssociateService;
import com.appkubes.mall.core.po.MallGoodsAssociate;
import com.appkubes.mall.core.po.MallGoodsAssociateExample;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class GoodsAssociateServiceImpl implements GoodsAssociateService {

    @Autowired
    GoodsAssociateDao goodsAssociateDao;

    @Override
    public List<GoodsAssociateDTO> getGoodList(String goodKey, String appKey) {
        return goodsAssociateDao.getList(goodKey, appKey);
    }

    @Override
    public GoodsAssociateDao getDao() {
        return goodsAssociateDao;
    }

    public void remove(String combinateKey) {
        goodsAssociateDao.deleteByPrimaryKey(combinateKey);
    }

    @Override
    public String add(MallGoodsAssociate goodsAssociate) {
        goodsAssociate.setAssociateKey(UUIDUtils.getUUID());
        goodsAssociate.setAppKey(null);
        goodsAssociateDao.insertSelective(goodsAssociate);
        return goodsAssociate.getAssociateKey();
    }

    @Override
    public List<MallGoodsAssociate> getList(String goodKey) {
        MallGoodsAssociateExample example = new MallGoodsAssociateExample();
        MallGoodsAssociateExample.Criteria criteria = example.createCriteria();
        criteria.andGoodKeyEqualTo(goodKey);
        return goodsAssociateDao.selectByExample(example);
    }
}
